home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Textra116 / Scripts / ScootTest.textra < prev    next >
Encoding:
Text File  |  1996-09-27  |  4.4 KB  |  182 lines

  1.     /*******************************************************************
  2.      *   TEXTRA AREXX script -- Mike Haas, 1991, All Rights Reserved.  *
  3.      * Freely distributable ONLY as a component of the TEXTRA package. *
  4.      * This banner may not be removed or altered (improvements to the  *
  5.      *    actual program welcome).  Please document and send to me.    *
  6.      *        !!! PLACE THIS FILE IN YOUR REXX: DIRECTORY !!!          *
  7.      *******************************************************************/
  8.  
  9. /* SCOOTTEST <num>
  10.  *
  11.  * SCOOTTEST reports if the lines in a selection would be moved to the left
  12.  * less than <num> by SCOOT when <num> is negative.  If some lines are moved
  13.  * less than others, then a SCOOT to the right won't restore the lines to
  14.  * orginal format.  To see what this means, try "SCOOT -8", followed by 
  15.  * "SCOOT 8" on these comment lines.  The askerisks will be smashed against
  16.  * the left margin, then misshapen.
  17.  *
  18.  * <num> should match the value used with SCOOT. Some examples:
  19.  *
  20.  *    scoottest -8
  21.  *    scoottest -4
  22.  *    scoottest -
  23.  *
  24.  * SCOOTing an entire 997-line C source file takes about 125 seconds.
  25.  * SCOOTTEST will check the same file in 29 seconds (Amiga 3000/25).
  26.  */
  27.  
  28. /* Converted from SCOOT.TEXTRA by Ron Charlton */
  29. /* 00001 mdh 10-nov-92  Added ability to cancel script */
  30. /* 00002 mdh 20-nov-92  check version (cause of 'CheckCancel') */
  31.  
  32. OPTIONS results
  33.  
  34. rex = 0; result = "NOTSUPPORTED"    /*00002*/
  35. textraversion
  36. parse var result maj min rex
  37. if (result == "NOTSUPPORTED") | (rex < 3) then do
  38.     notify "Textra V1.13 or later required for this script."
  39.     exit
  40. end
  41.  
  42.  
  43. tabchar = d2c(9)
  44.  
  45.  
  46. parse upper arg num         /* get the argument */
  47.  
  48. if (num == "") then
  49.     do
  50.         notify "Scoot: You must provide a negative number for <num>."
  51.         exit
  52.     end
  53.  
  54. else if (num == "-") then
  55.     do
  56.         prefs TabWidth read
  57.         num = -result        /* use tab width from prefs */
  58.     end
  59.  
  60. get select position   /* get the select boundary, if any */
  61.  
  62. if (result == "NO SELECT") then   /* is nothing selected? */
  63.  
  64.     do
  65.         get cursor position   /* nothing selected, get cursor pos */
  66.         parse var result   cursx ' ' cursy
  67.         LinesSelected = 0   /* means 'just cursor' */
  68.     
  69.     end
  70.     
  71. else
  72.  
  73.     do
  74.         /* yes, there is a selection, get it's boundaries */
  75.         parse var result   startx ' ' starty ' ' endx ' ' endy
  76.         LinesSelected = (endy - starty)
  77.     
  78.         /* if only the 'eol' of the previous line is selected
  79.            (nothing on this line is actually included, i.e. x==0),
  80.            then don't include it.
  81.         */
  82.         if (endx > 0) then  LinesSelected = LinesSelected + 1
  83.     
  84.     end
  85.  
  86. if (LinesSelected == 0) then
  87.  
  88.     do
  89.         currline = cursy
  90.         gotoxy 0 cursy
  91.         call scoottest
  92.         if (num > 0) then
  93.             gotoxy cursx+num cursy
  94.         else
  95.             do
  96.                 if (firstcharpos == 0) then
  97.                     gotoxy cursx cursy
  98.                 else
  99.                     gotoxy max(cursx+num,0) cursy
  100.             end
  101.     end
  102.  
  103. else
  104.  
  105.     do
  106.         currline = starty; numLeft = LinesSelected
  107.         do while (numLeft > 0)
  108.             do
  109.                 CheckCancel; if (result == CANCEL) then exit   /*00001*/
  110.                 gotoxy 0 currline
  111.                 call scoottest
  112.                 currline = currline + 1
  113.                 numLeft = numLeft - 1
  114.             end
  115.         end
  116.         gotoxy 0 starty
  117.         selectto 0 starty+LinesSelected
  118.     end
  119.     
  120. exit
  121.  
  122.  
  123. scoottest:
  124.  
  125.     get cursor char
  126.     if (result == "-1") then
  127.         /* empty line */
  128.         return
  129.     cursorchar = result
  130.     
  131.     if (cursorchar == ' ' | cursorchar == tabchar) then
  132.         do
  133.             hopto next char
  134.             if (result == "NOT FOUND") then
  135.                 /* at end of file */
  136.                 return
  137.         end
  138.  
  139.     get cursor position    
  140.     if (result == "SELECT") then
  141.         /* cannot (?) happen */
  142.         return
  143.  
  144.     parse var result   firstcharpos ' ' cursoryscoot
  145.     if (cursoryscoot ~= currline) then
  146.         /* nothing on currline */
  147.         return
  148.  
  149.     if (num < 0 & abs(num) > firstcharpos) then
  150.         do
  151.             if (LinesSelected > 0) then
  152.                 do
  153.                     ask "Line " || currline+1 || " cannot move left far enough. Continue test?" 
  154.                     if (result == "NO") then numLeft = 0
  155.                 end
  156.             else
  157.                 notify "Line " || currline+1 || " cannot move left far enough."
  158.         end
  159.  
  160. return
  161.  
  162. Debug: procedure
  163.     parse arg theString
  164.     get select position   /* get the select boundary, if any */
  165.     if (result == "NO SELECT") then   /* is nothing selected? */
  166.         do
  167.             get cursor position   /* nothing selected, get cursor pos */
  168.             parse var result   cursxdbg ' ' cursydbg
  169.             WasSelected = 0   /* means 'just cursor' */
  170.         end
  171.     else
  172.         do
  173.             /* yes, there is a selection, get it's boundaries */
  174.             parse var result   cursxdbg ' ' cursydbg ' ' endxdbg ' ' endydbg
  175.             WasSelected = 1
  176.         end
  177.     lastline
  178.     text theString
  179.     gotoxy cursxdbg cursydbg
  180.     if (WasSelected == 1) then   selectto endxdbg endydbg
  181. return
  182.